Centralize enable option handling in the factory#324
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
430542d to
dd508cf
Compare
dd508cf to
00679a8
Compare
yoannmoinet
left a comment
There was a problem hiding this comment.
Looks mostly good.
I wonder if we could handle one level higher than just resolveEnable and have something like a global validateOptions, that would, for now, validate enable.
It would be called from each plugin, but would be implemented, tested and documented just once.
Since this is a standard, this can be documented just at the root, once, and not for each individual plugin.
Or alternatively, handle this at the factory level directly, where we also have an validateOptions too.
build-plugins/packages/factory/src/index.ts
Lines 176 to 190 in 00679a8
This way, plugins themselves don't even have to handle it.
The standard is applied by design.
I think I prefer the factory approach after all.
WDYT?
Introduce a shared `resolveEnable` helper in @dd/core that all six user-facing plugins now use to resolve their `enable` config flag. This replaces the two divergent patterns (explicit `??` vs spread- override) with a single greppable call site per plugin. Non-boolean values continue to be coerced for backwards compatibility but now emit a deprecation warning so strict validation can land in the next major. live-debugger retains its existing hard rejection via the companion `validateEnableStrict` helper. Also fixes the misleading `default: true` wording in the output and metrics READMEs, adds the missing `errorTracking.enable` docs section, and authors a full README for the rum plugin (lost in the sourcemaps extraction refactor of 804f917).
00679a8 to
f847e1a
Compare
enable option handling across all pluginsenable option handling in the factory
jakub-g
left a comment
There was a problem hiding this comment.
I defer review to Yoann here :)
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |

What and why?
The six user-facing plugins (
apps,error-tracking,live-debugger,metrics,output,rum) each had a divergent implementation for resolving theirenableconfig boolean:appsandlive-debuggerused explicit??nullish coalescing, while the other four used a spread-override trick (enable: !!config[KEY], ...config[KEY]) that relies on property ordering.live-debuggerrejected non-boolean values; the rest silently coerced.outputandmetricsdocumenteddefault: true(misleading — it's false when the config block is absent), anderror-trackinghad noenablesection at all.This PR makes the factory the single owner of
enableresolution so every plugin shares one set of semantics — and individual plugins stop having to think aboutenableat all.How?
Factory becomes the gate (
@dd/factory):Each user-facing plugin's
<configKey>.enableis resolved once in the factory's plugin loop, before the plugin'sgetPluginsis even called. If it resolves tofalse, the plugin is never instantiated, never validated, never hooked in. As far as the rest of the build is concerned, it doesn't exist.Shared helper (
@dd/core/helpers/options):resolveEnable(options, configKey, log)— single source of truth used by the factory. Emits a deprecation warning (once per key) when a non-boolean value is passed, coercing it with!!to avoid breaking existing users. ATODO(next major)marks the coercion site for removal.Plugins simplified:
getPluginsno longer has anif (!validatedOptions.enable) return []guard.validateOptionsno longer callsresolveEnable;apps,output, andmetricsno longer need alogparameter at all.<Plugin>OptionsWithDefaultstype dropsenable— the factory guarantees it'struewhen plugin code runs, so it's meaningless in the resolved shape.live-debuggernow uses the same soft coercion as everyone else (with a deprecation warning) instead of throwing on non-boolean values. Strict rejection moves to the next major along with the others.Integrity tooling:
The
#configs-injection-markerblock now emits[name, CONFIG_KEY, getPlugins]triples so the factory's enable loop stays in sync as plugins are added or removed. Thecreate-pluginscaffolding follows the same pattern (noenableguard, noenableinOptionsWithDefaults).Documentation:
### <key>.enablesection with the correct default wording:truewhen a<key>config block is present,falseotherwise.error-trackinggained its missingenablesection and TOC entry.live-debugger's README updated to reflect the soft coercion (was "Must be a boolean").Tests:
enable: false→ skip,enable: true→ include, non-boolean → coerced + included.enabletests removed fromvalidate.test.ts/index.test.ts(no longer the plugin's contract).live-debugger's strict-rejection tests removed (no longer the contract).